#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H

#include <QMainWindow>
#include <QSqlTableModel>
#include "logmanager.h"

namespace Ui {
class DeviceManager;
}

class DeviceManager : public QMainWindow
{
    Q_OBJECT

public:
    explicit DeviceManager(QWidget *parent = nullptr);
    ~DeviceManager();

    // 添加设置当前用户ID的方法
    void setCurrentUserId(int userId);

    void setCurrentUserRole(const QString &role);
protected:
    void closeEvent(QCloseEvent *event) override;

private slots:
    void onOpenDatabase();
    void onAddDevice();
    void onDeleteDevice();
    void onSaveChanges();
    void onSearchDevice();
    void onAddGroup();
    void onDeleteGroup();
    void onGroupFilterChanged(int index);
    void onTabChanged(int index);

private:
    Ui::DeviceManager *ui;
    QSqlTableModel *deviceModel;
    QSqlTableModel *deviceManagementModel;
    QSqlTableModel *groupModel;

    // 添加当前用户ID
    int currentUserId = -1;

    void setupUI();
    void setupConnections();
    void setupDeviceModel();
    void setupDeviceManagementModel();
    void setupGroupModel();
    void editDeviceHeaderData(QSqlTableModel *model);

    QString currentUserRole;

    void applyUserPermissions();
};

#endif // DEVICEMANAGER_H
